<?php

use yii\helpers\Html;
use common\core\ActiveForm;
use common\helpers\ArrayHelper;
use backend\models\system\Menu;

/* @var $this yii\web\View */
/* @var $model backend\models\system\Menu */
/* @var $form yii\widgets\ActiveForm */

/* 加载页面级别资源 */
\backend\assets\Select2Asset::register($this);

?>

<div class="menu-form">

    <?php $form = ActiveForm::begin([
        'options' => [
            'class'=>"form-horizontal",
            'onkeydown' => "if(event.keyCode==13)return false;",
        ],
        'id' => 'create_update_form',
    ]); ?>

    <div class="panel panel-default">
        <div class="panel-body">
            <div class="row">
                <label class="col-sm-2 control-label"><span class="red">*</span>标题</label>
                <div class="col-xs-9 col-sm-3">
                    <?=$form->field($model, 'title')->textInput(['class'=>'form-control c-md-2'])->label(false)?>
                </div>
                <div class="col-xs-9 col-sm-6">
                    <div class="hint-block">栏目的标题</div>
                </div>
            </div>
            <div class="row">
                <label class="col-sm-2 control-label"><span class="red">*</span>排序值</label>
                <div class="col-xs-9 col-sm-3">
                    <?=$form->field($model, 'sort')->textInput(['class'=>'form-control c-md-1'])->label(false)?>
                </div>
                <div class="col-xs-9 col-sm-6">
                    <div class="hint-block">数值越小排序越前</div>
                </div>
            </div>
            <div class="row">
                <label class="col-sm-2 control-label"><span class="red">*</span>链接</label>
                <div class="col-xs-9 col-sm-3">
                    <?=$form->field($model, 'url')->textInput()->label(false)?>
                </div>
                <div class="col-xs-9 col-sm-6">
                    <div class="hint-block">格式：index/index&id=2&type=1</div>
                </div>
            </div>
            <div class="row">
                <label class="col-sm-2 control-label"><span class="red">*</span>上级菜单</label>
                <div class="col-xs-9 col-sm-3">
                    <?=$form->field($model, 'pid')->selectList(
                        ArrayHelper::merge(['0'=>'一级栏目'],ArrayHelper::listDataLevel( \backend\models\Menu::find()->asArray()->all(), 'id', 'title','id','pid')),
                        ['class'=>'form-control select2','widthclass'=>'c-md-2'])->label(false) ?>
                </div>
                <div class="col-xs-9 col-sm-6">
                    <div class="hint-block">上级菜单描述</div>
                </div>
            </div>

            <div class="row">
                <label class="col-sm-2 control-label"><span class="red">*</span>分组</label>
                <div class="col-xs-9 col-sm-3">
                    <?=$form->field($model, 'group')->textInput(['class'=>'form-control c-md-3'])->label(false)?>
                </div>
                <div class="col-xs-3 col-sm-6">
                    <div class="hint-block">格式为：分组名称|图标样式 ，例如：系统|icon-comment</div>
                </div>
            </div>

            <div class="row">
                <label class="col-sm-2 control-label"><span class="red">*</span>是否隐藏</label>
                <div class="col-xs-9 col-sm-3">
                    <?= $form->field($model, 'status')->radioList(Menu::getStatus())->label(false) ?>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-sm-offset-2 col-sm-10">
            <div class="form-group">
                <?= Html::submitButton('保 存', ['class' => 'btn btn-success btn-lg ajax-post','target-form'=>'form-horizontal']) ?>
            </div>
        </div>
    </div>
    <?php ActiveForm::end(); ?>

</div>

<script language="JavaScript">
    <?php $this->beginBlock(Yii::$app->controller->route) ?>

    jQuery(document).ready(function() {
        highlight_subnav('system/menu/index'); //子导航高亮
    });

    <?php
    $this->endBlock();
    $this->registerJs($this->blocks[Yii::$app->controller->route], \yii\web\View::POS_END);
    ?>
</script>
